package ui.provider;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

import ui.Activator;
import dao.EgnRstScenario;

public class SqlFileLabel extends LabelProvider{
	private Map<ImageDescriptor,Image> imageCache = new HashMap<ImageDescriptor,Image>();
	private Image image;
	
	@Override
	public Image getImage(Object element) {
		ImageDescriptor  imgDesc = null;

		File file = (File) element;
		
		if (file.isDirectory()) {
			imgDesc =Activator.getImageDescriptor("icons/used/folder.gif");
		}
		else imgDesc =Activator.getImageDescriptor("icons/used/file_obj.gif");
		
		if(!imageCache.containsKey(imgDesc)){
			image = imgDesc.createImage();
			imageCache.put(imgDesc,image);
		}
		return imageCache.get(imgDesc);	
	}

	@Override
	public String getText(Object element) {
		String fileName = ((File) element).getName();
		if (fileName.length() > 0) {
			return fileName;
		}
		return ((File) element).getPath();
	}
}
